#!/bin/bash
if test ! -f "$1"
then
 echo "Error: executable $1 does not exist."
 exit 1
fi
if test ! -f "$2"
then
 echo "Error: trace log $2 does not exist."
 exit 1
fi
EXECUTABLE="$1"
TRACELOG="$2"
ident=0
while read LINETYPE FADDR CADDR CTIME; do
# CDATE="$(date -Iseconds -d @${CTIME})"
 if test "${LINETYPE}" = "e"
 then
     FNAME="$(addr2line -f -e ${EXECUTABLE} ${FADDR}|head -1)"
     CLINE="$(addr2line -s -e ${EXECUTABLE} ${CADDR})"
     for (( c=1; c<=ident; c++)) ; do echo -n "+" ; done 
     printf "${FNAME}"
     echo
     ident=$((ident+2))
 fi
 if test "${LINETYPE}" = "x"
 then
     ident=$((ident-2))
 fi
done < "${TRACELOG}"
